package com.ruoyi.course.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.course.utils.RoleUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.course.domain.CdStudentTeacherCourse;
import com.ruoyi.course.service.ICdStudentTeacherCourseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * studentcourseController
 * 
 * @author ruoyi
 * @date 2023-12-18
 */
@RestController
@RequestMapping("/studentcourse/studentCourse")
public class CdStudentTeacherCourseController extends BaseController
{
    @Autowired
    private ICdStudentTeacherCourseService cdStudentTeacherCourseService;

    @Autowired
    private RoleUtils roleUtils;

    /**
     * 查询studentcourse列表
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:list')")
    @GetMapping("/list")
    public TableDataInfo list(CdStudentTeacherCourse cdStudentTeacherCourse)
    {
        startPage();
        List<CdStudentTeacherCourse> list = cdStudentTeacherCourseService.selectCdStudentTeacherCourseList(cdStudentTeacherCourse);
        return getDataTable(list);
    }

    /**
     * 导出studentcourse列表
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:export')")
    @Log(title = "studentcourse", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CdStudentTeacherCourse cdStudentTeacherCourse)
    {
        List<CdStudentTeacherCourse> list = cdStudentTeacherCourseService.selectCdStudentTeacherCourseList(cdStudentTeacherCourse);
        ExcelUtil<CdStudentTeacherCourse> util = new ExcelUtil<CdStudentTeacherCourse>(CdStudentTeacherCourse.class);
        util.exportExcel(response, list, "学生选课数据");
    }

    /**
     * 导入学生选课信息（关联 学生-教师-课程）
     * @param file
     * @return
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:export')")
    @RequestMapping("/import")
    public void importData(MultipartFile file) {
        cdStudentTeacherCourseService.importData(file);
    }

    /**
     * 获取studentcourse详细信息
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:query')")
    @GetMapping(value = "/{teacherId}")
    public AjaxResult getInfo(@PathVariable("teacherId") Long teacherId)
    {
        return success(cdStudentTeacherCourseService.selectCdStudentTeacherCourseByTeacherId(teacherId));
    }

    /**
     * 新增studentcourse
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:add')")
    @Log(title = "studentcourse", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CdStudentTeacherCourse cdStudentTeacherCourse)
    {
        return toAjax(cdStudentTeacherCourseService.insertCdStudentTeacherCourse(cdStudentTeacherCourse));
    }

    /**
     * 修改studentcourse
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:edit')")
    @Log(title = "studentcourse", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CdStudentTeacherCourse cdStudentTeacherCourse)
    {
        return toAjax(cdStudentTeacherCourseService.updateCdStudentTeacherCourse(cdStudentTeacherCourse));
    }

    /**
     * 删除studentcourse
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:remove')")
    @Log(title = "studentcourse", businessType = BusinessType.DELETE)
	@DeleteMapping("/{teacherIds}")
    public AjaxResult remove(@PathVariable Long[] teacherIds)
    {
        return toAjax(cdStudentTeacherCourseService.deleteCdStudentTeacherCourseByTeacherIds(teacherIds));
    }

    /**
     * 学生自己选的课程，老师查看所有
     * @return
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:list')")
    @GetMapping("listBySelf")
    public AjaxResult listBySelf() {
        CdStudentTeacherCourse cdStudentTeacherCourse = new CdStudentTeacherCourse();
        return AjaxResult.success(cdStudentTeacherCourseService.selectCdStudentTeacherCourseList(cdStudentTeacherCourse));
    }


    /**
     * 老师查看自己指导的课程
     * @return
     */
    @PreAuthorize("@ss.hasPermi('studentcourse:studentCourse:list')")
    @GetMapping("/listByTeacherSelf")
    public AjaxResult listByTeacherSelf() {
        return AjaxResult.success(cdStudentTeacherCourseService.listByTeacherSelf());
    }

}
